# -*- coding: utf8 -*-

class Table( object ):

    _engine = "MyISAM"
#    _engine = "InnoDB row_format=COMPRESSED"
#    _engine = "Aria"
#    _engine = "TokuDB"

    _table_name = None
    _db = None

    def __init__(self, db = None):
        if self._table_name is None:
            raise AttributeError("Define non-empty class variable '_table_name'")
        self._db = db
        pass

    def setDb(self, db):
        self._db = db
        return self

    def getEngine(self):
        return self._engine

    def getCustomDbInfo(self):
        return {}

    def clean( self ):

        cur = self.getCursor()
        cur.execute("DROP TABLE IF EXISTS %s" % self._table_name)
        cur.close()

        self.create()

        return self

    def vacuum( self ):
        cur = self.getCursor()
        cur.execute("OPTIMIZE TABLE %s" % self._table_name)
        cur.close()
        return True

    def close(self):
        return self

    def getConnection(self):
        return self._db.getConnection(self.getCustomDbInfo())

    def getCursor(self):
        return self._db.getCursor()

    def create( self ):
        raise NotImplemented

    pass
